# import urllib.request
#
# resp = urllib.request.urlopen('http://www.baidu.com')
#
# html = resp.read().decode('utf-8')
# # print(html)
# with open('baidu.html',mode='w',encoding='utf-8')as f:
#     f.write(html)

# import urllib.request
#
# resp = urllib.request.urlopen('http://www.baidu.com')
# html = resp.read().decode('utf-8')
# with open('baidu1.html',mode='w',encoding='utf-8') as f:
#     f.write(html)


# import urllib.request
#
# resp = urllib.request.urlopen('http://www.baidu.com')
# html = resp.read().decode('utf8')
# with open('badu2.html',mode='w',encoding='utf8')as f:
#     f.write(html)


#
# import urllib.request
# resp = urllib.request.urlopen('http://www.baidu.com')
# html = resp.read().decode('utf8')
# with open('badu3.html',mode='w',encoding='utf8')as f:
#     f.write(html)


# import urllib.request
# resp = urllib.request.urlopen('http://www.baidu.com')
# html = resp.read().decode('utf8')
# with open('baidu4.html',mode='w',encoding='utf8')as f:
#     f.write(html)

# import urllib.request
# resp = urllib.request.urlopen('http://home.firefoxchina.cn')
# html = resp.read().decode('utf-8')
# with open('fox.html',mode='w',encoding='utf-8')as f:
#     f.write(html)


# import urllib.request
# resp = urllib.request.urlopen('http://www.baidu.com')
# html = resp.read().decode('utf8')
# html = resp.readline(100).decode('utf8')
# print(resp.info())
# print(resp.geturl())
# print(resp.getcode())
# print(resp.getheaders())
# print(resp.getheader('set-cookie'))

# with open('baidu5.html',mode='w',encoding='utf8')as f:
#     f.write(html)

import urllib.parse
import urllib.request
data = bytes(urllib.parse.urlencode({'name':'夏洛','hobbies':'girl'}),encoding='utf8')
resp = urllib.request.urlopen('http://httpbin.org/post',data=data)
print(resp.read())
data = bytes(urllib.parse.urlencode({'name':'夏洛','happy':'美女','sex':'男'}),encoding='utf8')
print(data)